{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "import xgboost as xgb\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn import metrics\n",
    "from pandas.tseries.offsets import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 注意要把表中的 0 也都按空值 nan 处理，因为实际上不可能有真正有意义的 0 出现的！\n",
    "df = pd.read_csv(\"../../data/features/final_features_CB+OC.csv\", dtype={'sale_date':str}, na_values=['-',0], low_memory=False)\n",
    "df['sale_date']= pd.to_datetime(df['sale_date'])\n",
    "# df = df.drop('C_rcm_0', axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 5727 entries, 0 to 5726\n",
      "Columns: 1699 entries, class_id to month_oh_12\n",
      "dtypes: bool(1), datetime64[ns](1), float64(1663), int64(16), uint8(18)\n",
      "memory usage: 73.5 MB\n"
     ]
    }
   ],
   "source": [
    "# 单纯时间信息\n",
    "df['year'] = df['sale_date'].apply(lambda x:x.year)\n",
    "df['month'] = df['sale_date'].apply(lambda x:x.month)\n",
    "df['is_leap_year'] = df['sale_date'].apply(lambda x:x.is_leap_year)\n",
    "df['year_oh'] = df['year']\n",
    "df['month_oh'] = df['month']\n",
    "df = pd.get_dummies(df, columns=['year_oh','month_oh'])\n",
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 临时加一个把class_id做onehot的操作。\n",
    "# df = pd.get_dummies(df, columns=['class_id'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# %qtconsole\n",
    "# pd.Series(df.columns.values).to_csv('all_columns.txt', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 真正使用之前，还有最后一次机会，可以做特征的筛选！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 最后的特征筛选！\n",
    "# df = df[[blablabla]]\n",
    "# df = df.drop([blabla], axis=1)\n",
    "\n",
    "# drop = []\n",
    "# for i in range(37, 60):\n",
    "#     drop.append('C_som_' + str(i+1));\n",
    "#     drop.append('C_fd_' + str(i+1));\n",
    "#     drop.append('C_sd_' + str(i+1));\n",
    "#     drop.append('C_fr_' + str(i+1));\n",
    "#     drop.append('C_sr_' + str(i+1));\n",
    "#     drop.append('C_dfr_' + str(i+1));\n",
    "#     drop.append('C_rfd_' + str(i+1));\n",
    "#     drop.append('C_rcm_' + str(i+1));\n",
    "#     drop.append('C_rcm_fd_' + str(i+1));\n",
    "#     drop.append('C_rcm_sd_' + str(i+1));\n",
    "#     drop.append('C_rcm_fr_' + str(i+1));\n",
    "#     drop.append('C_rcm_sr_' + str(i+1));\n",
    "#     drop.append('C_rcm_dfr_' + str(i+1));\n",
    "#     drop.append('C_rcm_rfd_' + str(i+1));\n",
    "\n",
    "# df = df.drop(drop, axis=1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_backup = df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 又得切一次，现在要切成三部分：2017.10以前的，2017.10的，2017.11的\n",
    "# 第一步，得到验证集（2017.10）的 y\n",
    "val_y = df[df['sale_date'] == pd.to_datetime('201710', format='%Y%m')].groupby('class_id').sum()['sale_quantity'].apply(lambda x: 20*x)#.apply(np.log2)\n",
    "\n",
    "# 临时加一个把class_id做onehot的操作。\n",
    "df = pd.get_dummies(df, columns=['class_id'])\n",
    "\n",
    "# 第二步，得到训练集（2017.10以前）的 X 和 y\n",
    "df_train = df[df['sale_date'] < pd.to_datetime('201710', format='%Y%m')]\n",
    "# 第三步，得到验证集（2017.10）的 X\n",
    "val_X = df[df['sale_date'] == pd.to_datetime('201710', format='%Y%m')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 140 entries, 31 to 5725\n",
      "Columns: 1838 entries, sale_date to class_id_978089\n",
      "dtypes: bool(1), datetime64[ns](1), float64(1663), int64(15), uint8(158)\n",
      "memory usage: 1.8 MB\n"
     ]
    }
   ],
   "source": [
    "val_X.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "#处理训练集\n",
    "# df_train = df\n",
    "df_train = df_train.drop('sale_date', axis=1)\n",
    "y = df_train['sale_quantity'].apply(lambda x: 20*x).values#.apply(np.log2).values\n",
    "X = df_train.drop('sale_quantity', axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 5447 entries, 0 to 5724\n",
      "Columns: 1836 entries, C_som_1 to class_id_978089\n",
      "dtypes: bool(1), float64(1662), int64(15), uint8(158)\n",
      "memory usage: 70.6 MB\n"
     ]
    }
   ],
   "source": [
    "X.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "#构造验证集\n",
    "val_X = val_X.drop('sale_date', axis=1)\n",
    "val_X = val_X.drop('sale_quantity', axis=1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0]\ttrain-rmse:13129.7\tvalidation-rmse:10421.6\n",
      "Multiple eval metrics have been passed: 'validation-rmse' will be used for early stopping.\n",
      "\n",
      "Will train until validation-rmse hasn't improved in 20 rounds.\n",
      "[1]\ttrain-rmse:11972\tvalidation-rmse:9391.53\n",
      "[2]\ttrain-rmse:10923.7\tvalidation-rmse:8366.34\n",
      "[3]\ttrain-rmse:9977.6\tvalidation-rmse:7530.51\n",
      "[4]\ttrain-rmse:9126.59\tvalidation-rmse:6742.38\n",
      "[5]\ttrain-rmse:8365.61\tvalidation-rmse:6086.21\n",
      "[6]\ttrain-rmse:7682.9\tvalidation-rmse:5504.56\n",
      "[7]\ttrain-rmse:7070.67\tvalidation-rmse:4993.52\n",
      "[8]\ttrain-rmse:6515.32\tvalidation-rmse:4464.03\n",
      "[9]\ttrain-rmse:6017.21\tvalidation-rmse:3991.09\n",
      "[10]\ttrain-rmse:5564.27\tvalidation-rmse:3652.62\n",
      "[11]\ttrain-rmse:5161.38\tvalidation-rmse:3303.27\n",
      "[12]\ttrain-rmse:4797.4\tvalidation-rmse:3069.94\n",
      "[13]\ttrain-rmse:4479.57\tvalidation-rmse:2823.46\n",
      "[14]\ttrain-rmse:4188.11\tvalidation-rmse:2574.56\n",
      "[15]\ttrain-rmse:3928.92\tvalidation-rmse:2382.23\n",
      "[16]\ttrain-rmse:3698.31\tvalidation-rmse:2264.51\n",
      "[17]\ttrain-rmse:3490.96\tvalidation-rmse:2158\n",
      "[18]\ttrain-rmse:3295.11\tvalidation-rmse:2073.82\n",
      "[19]\ttrain-rmse:3124.58\tvalidation-rmse:2026.9\n",
      "[20]\ttrain-rmse:2972.78\tvalidation-rmse:2000.58\n",
      "[21]\ttrain-rmse:2838.56\tvalidation-rmse:1962.22\n",
      "[22]\ttrain-rmse:2717.08\tvalidation-rmse:1976.55\n",
      "[23]\ttrain-rmse:2605.71\tvalidation-rmse:1982.18\n",
      "[24]\ttrain-rmse:2513.42\tvalidation-rmse:1996.3\n",
      "[25]\ttrain-rmse:2427.59\tvalidation-rmse:1999.94\n",
      "[26]\ttrain-rmse:2349.31\tvalidation-rmse:2022.08\n",
      "[27]\ttrain-rmse:2279.51\tvalidation-rmse:2054\n",
      "[28]\ttrain-rmse:2218.18\tvalidation-rmse:2088.2\n",
      "[29]\ttrain-rmse:2170.45\tvalidation-rmse:2097.08\n",
      "[30]\ttrain-rmse:2126.63\tvalidation-rmse:2117.44\n",
      "[31]\ttrain-rmse:2080.31\tvalidation-rmse:2130.34\n",
      "[32]\ttrain-rmse:2042.02\tvalidation-rmse:2162.26\n",
      "[33]\ttrain-rmse:1997.8\tvalidation-rmse:2183.2\n",
      "[34]\ttrain-rmse:1959.43\tvalidation-rmse:2212.26\n",
      "[35]\ttrain-rmse:1921.79\tvalidation-rmse:2223.59\n",
      "[36]\ttrain-rmse:1892.97\tvalidation-rmse:2245.53\n",
      "[37]\ttrain-rmse:1863.02\tvalidation-rmse:2245.6\n",
      "[38]\ttrain-rmse:1841.93\tvalidation-rmse:2262.72\n",
      "[39]\ttrain-rmse:1816.66\tvalidation-rmse:2268.94\n",
      "[40]\ttrain-rmse:1791.53\tvalidation-rmse:2267.13\n",
      "[41]\ttrain-rmse:1771.67\tvalidation-rmse:2271.36\n",
      "Stopping. Best iteration:\n",
      "[21]\ttrain-rmse:2838.56\tvalidation-rmse:1962.22\n",
      "\n"
     ]
    }
   ],
   "source": [
    "dtrain = xgb.DMatrix(X, label=y, missing=np.nan) \n",
    "# dtest = xgb.DMatrix(df_test)\n",
    "dtest = xgb.DMatrix(val_X, label=val_y.values, missing=np.nan) \n",
    "param = {\n",
    "    'max_depth' : 6,\n",
    "    'eta' : 0.1, #0.02\n",
    "    'objective' : 'reg:linear',\n",
    "#     'objective':'binary:logistic',\n",
    "    'silent': 0,\n",
    "#     'nthread': 4,\n",
    "#     'booster': 'gbtree'\n",
    "}\n",
    "num_round = 8000 # v0.2 best 129  # 8000\n",
    "eval_set = [(dtrain, 'train'), (dtest, 'validation')]\n",
    "best = xgb.train(param, dtrain, num_round, verbose_eval=True, early_stopping_rounds=20, evals=eval_set)#early stop 200\n",
    "\n",
    "pred = best.predict(dtest).round(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 测试指数对数处理labels\n",
    "predSeries = pd.Series(pred)\n",
    "ps = predSeries.values#.apply(lambda x: 2**x)\n",
    "# ps = predSeries.apply(np.exp).values\n",
    "val_y2metric = val_y.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.55948553501277398"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 测试指数对数处理labels，计算最终结果\n",
    "# np.sqrt( metrics.mean_squared_error(np.log(val_y.apply(lambda x: 2**x).values), np.log(ps)))\n",
    "np.sqrt( metrics.mean_squared_error(np.log2(val_y2metric), np.log2(ps)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "119.86745656289344"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sqrt( metrics.mean_squared_error(val_y.values, pred))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x2370535f470>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%qtconsole\n",
    "import matplotlib.pyplot as plt\n",
    "fig, ax = plt.subplots(figsize=(30, 250))\n",
    "xgb.plot_importance(best, ax=ax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 看起来效果还不错！  \n",
    "### 那就用完整的数据集训练一个结果交上去试试。  \n",
    "### 迭代次数130，其他xgb参数同上。\n",
    "\n",
    "先他妈的构造完整的训练集和测试集。\n",
    "### 有部分特征需要重新生成！\n",
    "#### 目前是**涉及车型**的统计信息，需要重新生成\n",
    "\n",
    "### 生成特征的顺序是：\n",
    "1. 环比同比之类的时间+车型信息，存在tmp中（5727条） —— 这部分特征是可以在后面预测11月时直接用的\n",
    "2. 切分训练集、验证集/测试集出来\n",
    "2. 车型自身统计信息，存在ndf（140条）\n",
    "3. tmp.join(ndf)\n",
    "4. 时间信息，直接加在上一步的结果上的\n",
    "\n",
    "### 所以思路是：\n",
    "1. 先重新读数据进来，和一开始一样\n",
    "2. 切分训练集、测试集\n",
    "3. 统计车型信息\n",
    "4. tmp.join(ndf)\n",
    "5. 加上时间信息\n",
    "\n",
    "\n",
    "# 流程！\n",
    "1. 车型历史销量特征，从文件读取（5727行）\n",
    "2. 品牌历史销量特征，从文件读取（1600+行）\n",
    "3. join\n",
    "1. 最后是纯时间特征\n",
    "-----\n",
    "0. 备份全集于df_backup，因为下面要破坏，但后面还要用\n",
    "1. 切分训练集、验证集\n",
    "2. 训练并验证\n",
    "3. 切分训练集、测试集\n",
    "4. 测试集上跑出结果\n",
    "------\n",
    "+ 要么融合\n",
    "+ 要么加高斯\n",
    "+ 要么兼有"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = df_backup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 又得切一次，现在要切成2部分：2017.11以前的，2017.11的\n",
    "\n",
    "# # 第一步，得到验证集（2017.10）的 y\n",
    "# val_y = df[df['sale_date'] == pd.to_datetime('201710', format='%Y%m')].groupby('class_id').sum()['sale_quantity']\n",
    "\n",
    "# 第二步，得到训练集（2017.11以前）的 X 和 y\n",
    "df_train_total = df[df['sale_date'] < pd.to_datetime('201711', format='%Y%m')]\n",
    "\n",
    "# 第三步，得到测试集（2017.11）的 X\n",
    "test_X = df[df['sale_date'] == pd.to_datetime('201711', format='%Y%m')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# df_train_total = df\n",
    "df_train_total = df_train_total.drop('sale_date', axis=1)\n",
    "y_total = df_train_total['sale_quantity'].values\n",
    "X_total = df_train_total.drop('sale_quantity', axis=1)\n",
    "\n",
    "dtrain_total = xgb.DMatrix(X_total, label=y_total, missing=np.nan) \n",
    "\n",
    "test_X = test_X.drop('sale_date', axis=1)\n",
    "test_X = test_X.drop('sale_quantity', axis=1)\n",
    "dtest_total = xgb.DMatrix(test_X, missing=np.nan) \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0]\ttrain-rmse:704.736\n",
      "Will train until train-rmse hasn't improved in 250 rounds.\n",
      "[1]\ttrain-rmse:692.074\n",
      "[2]\ttrain-rmse:679.687\n",
      "[3]\ttrain-rmse:667.568\n",
      "[4]\ttrain-rmse:655.661\n",
      "[5]\ttrain-rmse:644.007\n",
      "[6]\ttrain-rmse:632.521\n",
      "[7]\ttrain-rmse:621.354\n",
      "[8]\ttrain-rmse:610.309\n",
      "[9]\ttrain-rmse:599.497\n",
      "[10]\ttrain-rmse:588.98\n",
      "[11]\ttrain-rmse:578.581\n",
      "[12]\ttrain-rmse:568.422\n",
      "[13]\ttrain-rmse:558.529\n",
      "[14]\ttrain-rmse:548.767\n",
      "[15]\ttrain-rmse:539.213\n",
      "[16]\ttrain-rmse:529.849\n",
      "[17]\ttrain-rmse:520.659\n",
      "[18]\ttrain-rmse:511.722\n",
      "[19]\ttrain-rmse:502.914\n",
      "[20]\ttrain-rmse:494.309\n",
      "[21]\ttrain-rmse:485.881\n",
      "[22]\ttrain-rmse:477.602\n",
      "[23]\ttrain-rmse:469.501\n",
      "[24]\ttrain-rmse:461.535\n",
      "[25]\ttrain-rmse:453.729\n",
      "[26]\ttrain-rmse:446.068\n",
      "[27]\ttrain-rmse:438.595\n",
      "[28]\ttrain-rmse:431.283\n",
      "[29]\ttrain-rmse:424.118\n",
      "[30]\ttrain-rmse:417.086\n",
      "[31]\ttrain-rmse:410.16\n",
      "[32]\ttrain-rmse:403.412\n",
      "[33]\ttrain-rmse:396.811\n",
      "[34]\ttrain-rmse:390.345\n",
      "[35]\ttrain-rmse:383.98\n",
      "[36]\ttrain-rmse:377.767\n",
      "[37]\ttrain-rmse:371.683\n",
      "[38]\ttrain-rmse:365.745\n",
      "[39]\ttrain-rmse:359.9\n",
      "[40]\ttrain-rmse:354.146\n",
      "[41]\ttrain-rmse:348.515\n",
      "[42]\ttrain-rmse:342.967\n",
      "[43]\ttrain-rmse:337.527\n",
      "[44]\ttrain-rmse:332.265\n",
      "[45]\ttrain-rmse:327.059\n",
      "[46]\ttrain-rmse:321.969\n",
      "[47]\ttrain-rmse:316.972\n",
      "[48]\ttrain-rmse:312.092\n",
      "[49]\ttrain-rmse:307.296\n",
      "[50]\ttrain-rmse:302.648\n",
      "[51]\ttrain-rmse:298.027\n",
      "[52]\ttrain-rmse:293.513\n",
      "[53]\ttrain-rmse:289.111\n",
      "[54]\ttrain-rmse:284.765\n",
      "[55]\ttrain-rmse:280.591\n",
      "[56]\ttrain-rmse:276.433\n",
      "[57]\ttrain-rmse:272.43\n",
      "[58]\ttrain-rmse:268.455\n",
      "[59]\ttrain-rmse:264.615\n",
      "[60]\ttrain-rmse:260.803\n",
      "[61]\ttrain-rmse:257.078\n",
      "[62]\ttrain-rmse:253.417\n",
      "[63]\ttrain-rmse:249.844\n",
      "[64]\ttrain-rmse:246.336\n",
      "[65]\ttrain-rmse:242.958\n",
      "[66]\ttrain-rmse:239.567\n",
      "[67]\ttrain-rmse:236.277\n",
      "[68]\ttrain-rmse:233.066\n",
      "[69]\ttrain-rmse:229.89\n",
      "[70]\ttrain-rmse:226.767\n",
      "[71]\ttrain-rmse:223.747\n",
      "[72]\ttrain-rmse:220.843\n",
      "[73]\ttrain-rmse:217.948\n",
      "[74]\ttrain-rmse:215.109\n",
      "[75]\ttrain-rmse:212.339\n",
      "[76]\ttrain-rmse:209.679\n",
      "[77]\ttrain-rmse:206.994\n",
      "[78]\ttrain-rmse:204.43\n",
      "[79]\ttrain-rmse:201.866\n",
      "[80]\ttrain-rmse:199.394\n",
      "[81]\ttrain-rmse:196.956\n",
      "[82]\ttrain-rmse:194.576\n",
      "[83]\ttrain-rmse:192.202\n",
      "[84]\ttrain-rmse:189.915\n",
      "[85]\ttrain-rmse:187.683\n",
      "[86]\ttrain-rmse:185.516\n",
      "[87]\ttrain-rmse:183.361\n",
      "[88]\ttrain-rmse:181.239\n",
      "[89]\ttrain-rmse:179.14\n",
      "[90]\ttrain-rmse:177.118\n",
      "[91]\ttrain-rmse:175.104\n",
      "[92]\ttrain-rmse:173.185\n",
      "[93]\ttrain-rmse:171.311\n",
      "[94]\ttrain-rmse:169.451\n",
      "[95]\ttrain-rmse:167.6\n",
      "[96]\ttrain-rmse:165.853\n",
      "[97]\ttrain-rmse:164.097\n",
      "[98]\ttrain-rmse:162.4\n",
      "[99]\ttrain-rmse:160.742\n",
      "[100]\ttrain-rmse:159.085\n",
      "[101]\ttrain-rmse:157.51\n",
      "[102]\ttrain-rmse:155.946\n",
      "[103]\ttrain-rmse:154.417\n",
      "[104]\ttrain-rmse:152.913\n",
      "[105]\ttrain-rmse:151.44\n",
      "[106]\ttrain-rmse:149.999\n",
      "[107]\ttrain-rmse:148.547\n",
      "[108]\ttrain-rmse:147.154\n",
      "[109]\ttrain-rmse:145.856\n",
      "[110]\ttrain-rmse:144.566\n",
      "[111]\ttrain-rmse:143.291\n",
      "[112]\ttrain-rmse:141.982\n",
      "[113]\ttrain-rmse:140.741\n",
      "[114]\ttrain-rmse:139.475\n",
      "[115]\ttrain-rmse:138.336\n",
      "[116]\ttrain-rmse:137.15\n",
      "[117]\ttrain-rmse:135.992\n",
      "[118]\ttrain-rmse:134.922\n",
      "[119]\ttrain-rmse:133.838\n",
      "[120]\ttrain-rmse:132.819\n",
      "[121]\ttrain-rmse:131.786\n",
      "[122]\ttrain-rmse:130.754\n",
      "[123]\ttrain-rmse:129.805\n",
      "[124]\ttrain-rmse:128.81\n",
      "[125]\ttrain-rmse:127.91\n",
      "[126]\ttrain-rmse:126.987\n",
      "[127]\ttrain-rmse:126.054\n",
      "[128]\ttrain-rmse:125.188\n",
      "[129]\ttrain-rmse:124.341\n"
     ]
    }
   ],
   "source": [
    "param = {\n",
    "    'max_depth' : 6,\n",
    "    'eta' : 0.02,\n",
    "    'objective' : 'reg:linear',\n",
    "#     'objective':'binary:logistic',\n",
    "    'silent': 0,\n",
    "#     'nthread': 4,\n",
    "#     'booster': 'gbtree'\n",
    "}\n",
    "num_round = 130\n",
    "\n",
    "eval_set = [(dtrain_total, 'train')]\n",
    "best = xgb.train(param, dtrain, num_round, verbose_eval=True, early_stopping_rounds=250, evals=eval_set)\n",
    "\n",
    "pred_Nov = best.predict(dtest_total).round(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "res = pd.read_csv('../../data/origin/yancheng_testA_20171225.csv')\n",
    "res['predict_quantity'] = pred_Nov\n",
    "res.to_csv(\"../../result/v0.5.csv\",index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 简单ensemble一波"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "res1 = pd.read_csv('../../result/Oct_mul_115percents.csv')\n",
    "pred1 = res1['predict_quantity']\n",
    "\n",
    "res2 = pd.read_csv('../../result/v0.3.csv')\n",
    "pred2 = res2['predict_quantity']\n",
    "\n",
    "final_pred = pd.Series(0.6*pred1 +  0.4*pred2).round(0).values\n",
    "\n",
    "\n",
    "res = pd.read_csv('../../data/origin/yancheng_testA_20171225.csv')\n",
    "res['predict_quantity'] = final_pred\n",
    "res.to_csv(\"../../result/Ensembled_0.6oct+0.4v0.3.csv\",index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "用十一月的好结果乘以1.4，作为十二月的。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>predict_date</th>\n",
       "      <th>class_id</th>\n",
       "      <th>predict_quantity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201712</td>\n",
       "      <td>281792</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201712</td>\n",
       "      <td>682651</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201712</td>\n",
       "      <td>603972</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201712</td>\n",
       "      <td>221795</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201712</td>\n",
       "      <td>482497</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>201712</td>\n",
       "      <td>379265</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>201712</td>\n",
       "      <td>687270</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>201712</td>\n",
       "      <td>890189</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>201712</td>\n",
       "      <td>654134</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>201712</td>\n",
       "      <td>739296</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>201712</td>\n",
       "      <td>437063</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>201712</td>\n",
       "      <td>453752</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>201712</td>\n",
       "      <td>209945</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>201712</td>\n",
       "      <td>732758</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>201712</td>\n",
       "      <td>683364</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>201712</td>\n",
       "      <td>527765</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>201712</td>\n",
       "      <td>614059</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>201712</td>\n",
       "      <td>527809</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>201712</td>\n",
       "      <td>401052</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>201712</td>\n",
       "      <td>510309</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>201712</td>\n",
       "      <td>290854</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>201712</td>\n",
       "      <td>416749</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>201712</td>\n",
       "      <td>587678</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>201712</td>\n",
       "      <td>651347</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>201712</td>\n",
       "      <td>973106</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>201712</td>\n",
       "      <td>854079</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>201712</td>\n",
       "      <td>713651</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>201712</td>\n",
       "      <td>468392</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>201712</td>\n",
       "      <td>169673</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>201712</td>\n",
       "      <td>379876</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>110</th>\n",
       "      <td>201712</td>\n",
       "      <td>417803</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>201712</td>\n",
       "      <td>492952</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>201712</td>\n",
       "      <td>580634</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>201712</td>\n",
       "      <td>559132</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>201712</td>\n",
       "      <td>961362</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>201712</td>\n",
       "      <td>354068</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>201712</td>\n",
       "      <td>348641</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>201712</td>\n",
       "      <td>861459</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>118</th>\n",
       "      <td>201712</td>\n",
       "      <td>950264</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>201712</td>\n",
       "      <td>760412</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>120</th>\n",
       "      <td>201712</td>\n",
       "      <td>560265</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>121</th>\n",
       "      <td>201712</td>\n",
       "      <td>376193</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>122</th>\n",
       "      <td>201712</td>\n",
       "      <td>872180</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>201712</td>\n",
       "      <td>621073</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>201712</td>\n",
       "      <td>516750</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>125</th>\n",
       "      <td>201712</td>\n",
       "      <td>270690</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>126</th>\n",
       "      <td>201712</td>\n",
       "      <td>178529</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>127</th>\n",
       "      <td>201712</td>\n",
       "      <td>786351</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>128</th>\n",
       "      <td>201712</td>\n",
       "      <td>526401</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>129</th>\n",
       "      <td>201712</td>\n",
       "      <td>436105</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>130</th>\n",
       "      <td>201712</td>\n",
       "      <td>194450</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>201712</td>\n",
       "      <td>963845</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>201712</td>\n",
       "      <td>349023</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>133</th>\n",
       "      <td>201712</td>\n",
       "      <td>743957</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>134</th>\n",
       "      <td>201712</td>\n",
       "      <td>923841</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>201712</td>\n",
       "      <td>250658</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>201712</td>\n",
       "      <td>714150</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>201712</td>\n",
       "      <td>395234</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>138</th>\n",
       "      <td>201712</td>\n",
       "      <td>842246</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139</th>\n",
       "      <td>201712</td>\n",
       "      <td>136916</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>140 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     predict_date  class_id  predict_quantity\n",
       "0          201712    281792               NaN\n",
       "1          201712    682651               NaN\n",
       "2          201712    603972               NaN\n",
       "3          201712    221795               NaN\n",
       "4          201712    482497               NaN\n",
       "5          201712    379265               NaN\n",
       "6          201712    687270               NaN\n",
       "7          201712    890189               NaN\n",
       "8          201712    654134               NaN\n",
       "9          201712    739296               NaN\n",
       "10         201712    437063               NaN\n",
       "11         201712    453752               NaN\n",
       "12         201712    209945               NaN\n",
       "13         201712    732758               NaN\n",
       "14         201712    683364               NaN\n",
       "15         201712    527765               NaN\n",
       "16         201712    614059               NaN\n",
       "17         201712    527809               NaN\n",
       "18         201712    401052               NaN\n",
       "19         201712    510309               NaN\n",
       "20         201712    290854               NaN\n",
       "21         201712    416749               NaN\n",
       "22         201712    587678               NaN\n",
       "23         201712    651347               NaN\n",
       "24         201712    973106               NaN\n",
       "25         201712    854079               NaN\n",
       "26         201712    713651               NaN\n",
       "27         201712    468392               NaN\n",
       "28         201712    169673               NaN\n",
       "29         201712    379876               NaN\n",
       "..            ...       ...               ...\n",
       "110        201712    417803               NaN\n",
       "111        201712    492952               NaN\n",
       "112        201712    580634               NaN\n",
       "113        201712    559132               NaN\n",
       "114        201712    961362               NaN\n",
       "115        201712    354068               NaN\n",
       "116        201712    348641               NaN\n",
       "117        201712    861459               NaN\n",
       "118        201712    950264               NaN\n",
       "119        201712    760412               NaN\n",
       "120        201712    560265               NaN\n",
       "121        201712    376193               NaN\n",
       "122        201712    872180               NaN\n",
       "123        201712    621073               NaN\n",
       "124        201712    516750               NaN\n",
       "125        201712    270690               NaN\n",
       "126        201712    178529               NaN\n",
       "127        201712    786351               NaN\n",
       "128        201712    526401               NaN\n",
       "129        201712    436105               NaN\n",
       "130        201712    194450               NaN\n",
       "131        201712    963845               NaN\n",
       "132        201712    349023               NaN\n",
       "133        201712    743957               NaN\n",
       "134        201712    923841               NaN\n",
       "135        201712    250658               NaN\n",
       "136        201712    714150               NaN\n",
       "137        201712    395234               NaN\n",
       "138        201712    842246               NaN\n",
       "139        201712    136916               NaN\n",
       "\n",
       "[140 rows x 3 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dec = pd.read_csv('../../data/origin/yancheng_testB_20180224.csv')\n",
    "dec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>predict_date</th>\n",
       "      <th>class_id</th>\n",
       "      <th>predict_quantity</th>\n",
       "      <th>tmp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201711</td>\n",
       "      <td>103507</td>\n",
       "      <td>206.0</td>\n",
       "      <td>288.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201711</td>\n",
       "      <td>124140</td>\n",
       "      <td>279.0</td>\n",
       "      <td>390.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201711</td>\n",
       "      <td>125403</td>\n",
       "      <td>194.0</td>\n",
       "      <td>271.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201711</td>\n",
       "      <td>136916</td>\n",
       "      <td>177.0</td>\n",
       "      <td>247.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201711</td>\n",
       "      <td>169673</td>\n",
       "      <td>168.0</td>\n",
       "      <td>235.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>201711</td>\n",
       "      <td>175962</td>\n",
       "      <td>250.0</td>\n",
       "      <td>350.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>201711</td>\n",
       "      <td>178529</td>\n",
       "      <td>183.0</td>\n",
       "      <td>256.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>201711</td>\n",
       "      <td>186250</td>\n",
       "      <td>109.0</td>\n",
       "      <td>152.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>201711</td>\n",
       "      <td>194201</td>\n",
       "      <td>396.0</td>\n",
       "      <td>554.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>201711</td>\n",
       "      <td>194450</td>\n",
       "      <td>293.0</td>\n",
       "      <td>410.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>201711</td>\n",
       "      <td>198427</td>\n",
       "      <td>114.0</td>\n",
       "      <td>159.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>201711</td>\n",
       "      <td>206765</td>\n",
       "      <td>2170.0</td>\n",
       "      <td>3038.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>201711</td>\n",
       "      <td>209945</td>\n",
       "      <td>144.0</td>\n",
       "      <td>201.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>201711</td>\n",
       "      <td>219195</td>\n",
       "      <td>150.0</td>\n",
       "      <td>210.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>201711</td>\n",
       "      <td>221795</td>\n",
       "      <td>406.0</td>\n",
       "      <td>568.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>201711</td>\n",
       "      <td>245609</td>\n",
       "      <td>130.0</td>\n",
       "      <td>182.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>201711</td>\n",
       "      <td>248352</td>\n",
       "      <td>312.0</td>\n",
       "      <td>436.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>201711</td>\n",
       "      <td>249875</td>\n",
       "      <td>148.0</td>\n",
       "      <td>207.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>201711</td>\n",
       "      <td>250658</td>\n",
       "      <td>208.0</td>\n",
       "      <td>291.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>201711</td>\n",
       "      <td>265980</td>\n",
       "      <td>251.0</td>\n",
       "      <td>351.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>201711</td>\n",
       "      <td>270690</td>\n",
       "      <td>690.0</td>\n",
       "      <td>966.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>201711</td>\n",
       "      <td>281301</td>\n",
       "      <td>432.0</td>\n",
       "      <td>604.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>201711</td>\n",
       "      <td>281792</td>\n",
       "      <td>470.0</td>\n",
       "      <td>658.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>201711</td>\n",
       "      <td>289386</td>\n",
       "      <td>444.0</td>\n",
       "      <td>621.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>201711</td>\n",
       "      <td>289403</td>\n",
       "      <td>281.0</td>\n",
       "      <td>393.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>201711</td>\n",
       "      <td>290854</td>\n",
       "      <td>232.0</td>\n",
       "      <td>324.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>201711</td>\n",
       "      <td>291086</td>\n",
       "      <td>390.0</td>\n",
       "      <td>546.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>201711</td>\n",
       "      <td>291514</td>\n",
       "      <td>63.0</td>\n",
       "      <td>88.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>201711</td>\n",
       "      <td>302513</td>\n",
       "      <td>174.0</td>\n",
       "      <td>243.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>201711</td>\n",
       "      <td>304458</td>\n",
       "      <td>438.0</td>\n",
       "      <td>613.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>110</th>\n",
       "      <td>201711</td>\n",
       "      <td>745137</td>\n",
       "      <td>903.0</td>\n",
       "      <td>1264.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>201711</td>\n",
       "      <td>750340</td>\n",
       "      <td>117.0</td>\n",
       "      <td>163.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>201711</td>\n",
       "      <td>760412</td>\n",
       "      <td>76.0</td>\n",
       "      <td>106.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>201711</td>\n",
       "      <td>786351</td>\n",
       "      <td>158.0</td>\n",
       "      <td>221.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>201711</td>\n",
       "      <td>789290</td>\n",
       "      <td>84.0</td>\n",
       "      <td>117.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>201711</td>\n",
       "      <td>810398</td>\n",
       "      <td>122.0</td>\n",
       "      <td>170.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>201711</td>\n",
       "      <td>815230</td>\n",
       "      <td>174.0</td>\n",
       "      <td>243.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>201711</td>\n",
       "      <td>819061</td>\n",
       "      <td>152.0</td>\n",
       "      <td>212.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>118</th>\n",
       "      <td>201711</td>\n",
       "      <td>842246</td>\n",
       "      <td>151.0</td>\n",
       "      <td>211.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>201711</td>\n",
       "      <td>851857</td>\n",
       "      <td>192.0</td>\n",
       "      <td>268.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>120</th>\n",
       "      <td>201711</td>\n",
       "      <td>854079</td>\n",
       "      <td>200.0</td>\n",
       "      <td>280.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>121</th>\n",
       "      <td>201711</td>\n",
       "      <td>854548</td>\n",
       "      <td>130.0</td>\n",
       "      <td>182.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>122</th>\n",
       "      <td>201711</td>\n",
       "      <td>861459</td>\n",
       "      <td>264.0</td>\n",
       "      <td>369.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>201711</td>\n",
       "      <td>871642</td>\n",
       "      <td>167.0</td>\n",
       "      <td>233.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>201711</td>\n",
       "      <td>872180</td>\n",
       "      <td>146.0</td>\n",
       "      <td>204.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>125</th>\n",
       "      <td>201711</td>\n",
       "      <td>883691</td>\n",
       "      <td>282.0</td>\n",
       "      <td>394.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>126</th>\n",
       "      <td>201711</td>\n",
       "      <td>890189</td>\n",
       "      <td>1358.0</td>\n",
       "      <td>1901.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>127</th>\n",
       "      <td>201711</td>\n",
       "      <td>905061</td>\n",
       "      <td>333.0</td>\n",
       "      <td>466.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>128</th>\n",
       "      <td>201711</td>\n",
       "      <td>905745</td>\n",
       "      <td>184.0</td>\n",
       "      <td>257.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>129</th>\n",
       "      <td>201711</td>\n",
       "      <td>914348</td>\n",
       "      <td>574.0</td>\n",
       "      <td>803.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>130</th>\n",
       "      <td>201711</td>\n",
       "      <td>923841</td>\n",
       "      <td>663.0</td>\n",
       "      <td>928.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>201711</td>\n",
       "      <td>924154</td>\n",
       "      <td>1204.0</td>\n",
       "      <td>1685.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>201711</td>\n",
       "      <td>948936</td>\n",
       "      <td>89.0</td>\n",
       "      <td>124.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>133</th>\n",
       "      <td>201711</td>\n",
       "      <td>950264</td>\n",
       "      <td>1147.0</td>\n",
       "      <td>1605.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>134</th>\n",
       "      <td>201711</td>\n",
       "      <td>953842</td>\n",
       "      <td>1102.0</td>\n",
       "      <td>1542.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>201711</td>\n",
       "      <td>961362</td>\n",
       "      <td>83.0</td>\n",
       "      <td>116.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>201711</td>\n",
       "      <td>961962</td>\n",
       "      <td>98.0</td>\n",
       "      <td>137.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>201711</td>\n",
       "      <td>963845</td>\n",
       "      <td>237.0</td>\n",
       "      <td>331.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>138</th>\n",
       "      <td>201711</td>\n",
       "      <td>973106</td>\n",
       "      <td>134.0</td>\n",
       "      <td>187.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139</th>\n",
       "      <td>201711</td>\n",
       "      <td>978089</td>\n",
       "      <td>433.0</td>\n",
       "      <td>606.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>140 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     predict_date  class_id  predict_quantity     tmp\n",
       "0          201711    103507             206.0   288.4\n",
       "1          201711    124140             279.0   390.6\n",
       "2          201711    125403             194.0   271.6\n",
       "3          201711    136916             177.0   247.8\n",
       "4          201711    169673             168.0   235.2\n",
       "5          201711    175962             250.0   350.0\n",
       "6          201711    178529             183.0   256.2\n",
       "7          201711    186250             109.0   152.6\n",
       "8          201711    194201             396.0   554.4\n",
       "9          201711    194450             293.0   410.2\n",
       "10         201711    198427             114.0   159.6\n",
       "11         201711    206765            2170.0  3038.0\n",
       "12         201711    209945             144.0   201.6\n",
       "13         201711    219195             150.0   210.0\n",
       "14         201711    221795             406.0   568.4\n",
       "15         201711    245609             130.0   182.0\n",
       "16         201711    248352             312.0   436.8\n",
       "17         201711    249875             148.0   207.2\n",
       "18         201711    250658             208.0   291.2\n",
       "19         201711    265980             251.0   351.4\n",
       "20         201711    270690             690.0   966.0\n",
       "21         201711    281301             432.0   604.8\n",
       "22         201711    281792             470.0   658.0\n",
       "23         201711    289386             444.0   621.6\n",
       "24         201711    289403             281.0   393.4\n",
       "25         201711    290854             232.0   324.8\n",
       "26         201711    291086             390.0   546.0\n",
       "27         201711    291514              63.0    88.2\n",
       "28         201711    302513             174.0   243.6\n",
       "29         201711    304458             438.0   613.2\n",
       "..            ...       ...               ...     ...\n",
       "110        201711    745137             903.0  1264.2\n",
       "111        201711    750340             117.0   163.8\n",
       "112        201711    760412              76.0   106.4\n",
       "113        201711    786351             158.0   221.2\n",
       "114        201711    789290              84.0   117.6\n",
       "115        201711    810398             122.0   170.8\n",
       "116        201711    815230             174.0   243.6\n",
       "117        201711    819061             152.0   212.8\n",
       "118        201711    842246             151.0   211.4\n",
       "119        201711    851857             192.0   268.8\n",
       "120        201711    854079             200.0   280.0\n",
       "121        201711    854548             130.0   182.0\n",
       "122        201711    861459             264.0   369.6\n",
       "123        201711    871642             167.0   233.8\n",
       "124        201711    872180             146.0   204.4\n",
       "125        201711    883691             282.0   394.8\n",
       "126        201711    890189            1358.0  1901.2\n",
       "127        201711    905061             333.0   466.2\n",
       "128        201711    905745             184.0   257.6\n",
       "129        201711    914348             574.0   803.6\n",
       "130        201711    923841             663.0   928.2\n",
       "131        201711    924154            1204.0  1685.6\n",
       "132        201711    948936              89.0   124.6\n",
       "133        201711    950264            1147.0  1605.8\n",
       "134        201711    953842            1102.0  1542.8\n",
       "135        201711    961362              83.0   116.2\n",
       "136        201711    961962              98.0   137.2\n",
       "137        201711    963845             237.0   331.8\n",
       "138        201711    973106             134.0   187.6\n",
       "139        201711    978089             433.0   606.2\n",
       "\n",
       "[140 rows x 4 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nov_pred = pd.read_csv('../../result/20180202_half_ensemble.csv')\n",
    "nov_pred['tmp'] = nov_pred['predict_quantity'] * 1.4\n",
    "nov_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>predict_date</th>\n",
       "      <th>class_id</th>\n",
       "      <th>predict_quantity</th>\n",
       "      <th>tmp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201712</td>\n",
       "      <td>281792</td>\n",
       "      <td>658.0</td>\n",
       "      <td>658.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201712</td>\n",
       "      <td>682651</td>\n",
       "      <td>449.0</td>\n",
       "      <td>449.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201712</td>\n",
       "      <td>603972</td>\n",
       "      <td>647.0</td>\n",
       "      <td>646.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201712</td>\n",
       "      <td>221795</td>\n",
       "      <td>568.0</td>\n",
       "      <td>568.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201712</td>\n",
       "      <td>482497</td>\n",
       "      <td>286.0</td>\n",
       "      <td>285.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>201712</td>\n",
       "      <td>379265</td>\n",
       "      <td>480.0</td>\n",
       "      <td>480.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>201712</td>\n",
       "      <td>687270</td>\n",
       "      <td>659.0</td>\n",
       "      <td>659.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>201712</td>\n",
       "      <td>890189</td>\n",
       "      <td>1901.0</td>\n",
       "      <td>1901.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>201712</td>\n",
       "      <td>654134</td>\n",
       "      <td>895.0</td>\n",
       "      <td>894.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>201712</td>\n",
       "      <td>739296</td>\n",
       "      <td>1260.0</td>\n",
       "      <td>1260.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>201712</td>\n",
       "      <td>437063</td>\n",
       "      <td>171.0</td>\n",
       "      <td>170.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>201712</td>\n",
       "      <td>453752</td>\n",
       "      <td>322.0</td>\n",
       "      <td>322.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>201712</td>\n",
       "      <td>209945</td>\n",
       "      <td>202.0</td>\n",
       "      <td>201.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>201712</td>\n",
       "      <td>732758</td>\n",
       "      <td>263.0</td>\n",
       "      <td>263.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>201712</td>\n",
       "      <td>683364</td>\n",
       "      <td>134.0</td>\n",
       "      <td>134.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>201712</td>\n",
       "      <td>527765</td>\n",
       "      <td>101.0</td>\n",
       "      <td>100.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>201712</td>\n",
       "      <td>614059</td>\n",
       "      <td>482.0</td>\n",
       "      <td>481.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>201712</td>\n",
       "      <td>527809</td>\n",
       "      <td>256.0</td>\n",
       "      <td>256.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>201712</td>\n",
       "      <td>401052</td>\n",
       "      <td>204.0</td>\n",
       "      <td>204.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>201712</td>\n",
       "      <td>510309</td>\n",
       "      <td>171.0</td>\n",
       "      <td>170.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>201712</td>\n",
       "      <td>290854</td>\n",
       "      <td>325.0</td>\n",
       "      <td>324.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>201712</td>\n",
       "      <td>416749</td>\n",
       "      <td>328.0</td>\n",
       "      <td>327.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>201712</td>\n",
       "      <td>587678</td>\n",
       "      <td>288.0</td>\n",
       "      <td>288.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>201712</td>\n",
       "      <td>651347</td>\n",
       "      <td>294.0</td>\n",
       "      <td>294.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>201712</td>\n",
       "      <td>973106</td>\n",
       "      <td>188.0</td>\n",
       "      <td>187.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>201712</td>\n",
       "      <td>854079</td>\n",
       "      <td>280.0</td>\n",
       "      <td>280.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>201712</td>\n",
       "      <td>713651</td>\n",
       "      <td>305.0</td>\n",
       "      <td>305.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>201712</td>\n",
       "      <td>468392</td>\n",
       "      <td>255.0</td>\n",
       "      <td>254.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>201712</td>\n",
       "      <td>169673</td>\n",
       "      <td>235.0</td>\n",
       "      <td>235.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>201712</td>\n",
       "      <td>379876</td>\n",
       "      <td>211.0</td>\n",
       "      <td>211.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>110</th>\n",
       "      <td>201712</td>\n",
       "      <td>417803</td>\n",
       "      <td>171.0</td>\n",
       "      <td>170.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>201712</td>\n",
       "      <td>492952</td>\n",
       "      <td>255.0</td>\n",
       "      <td>254.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>201712</td>\n",
       "      <td>580634</td>\n",
       "      <td>377.0</td>\n",
       "      <td>376.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>201712</td>\n",
       "      <td>559132</td>\n",
       "      <td>182.0</td>\n",
       "      <td>182.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>201712</td>\n",
       "      <td>961362</td>\n",
       "      <td>116.0</td>\n",
       "      <td>116.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>201712</td>\n",
       "      <td>354068</td>\n",
       "      <td>862.0</td>\n",
       "      <td>862.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>201712</td>\n",
       "      <td>348641</td>\n",
       "      <td>526.0</td>\n",
       "      <td>526.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>201712</td>\n",
       "      <td>861459</td>\n",
       "      <td>370.0</td>\n",
       "      <td>369.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>118</th>\n",
       "      <td>201712</td>\n",
       "      <td>950264</td>\n",
       "      <td>1606.0</td>\n",
       "      <td>1605.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>201712</td>\n",
       "      <td>760412</td>\n",
       "      <td>106.0</td>\n",
       "      <td>106.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>120</th>\n",
       "      <td>201712</td>\n",
       "      <td>560265</td>\n",
       "      <td>134.0</td>\n",
       "      <td>134.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>121</th>\n",
       "      <td>201712</td>\n",
       "      <td>376193</td>\n",
       "      <td>160.0</td>\n",
       "      <td>159.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>122</th>\n",
       "      <td>201712</td>\n",
       "      <td>872180</td>\n",
       "      <td>204.0</td>\n",
       "      <td>204.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>201712</td>\n",
       "      <td>621073</td>\n",
       "      <td>1644.0</td>\n",
       "      <td>1643.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>201712</td>\n",
       "      <td>516750</td>\n",
       "      <td>111.0</td>\n",
       "      <td>110.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>125</th>\n",
       "      <td>201712</td>\n",
       "      <td>270690</td>\n",
       "      <td>966.0</td>\n",
       "      <td>966.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>126</th>\n",
       "      <td>201712</td>\n",
       "      <td>178529</td>\n",
       "      <td>256.0</td>\n",
       "      <td>256.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>127</th>\n",
       "      <td>201712</td>\n",
       "      <td>786351</td>\n",
       "      <td>221.0</td>\n",
       "      <td>221.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>128</th>\n",
       "      <td>201712</td>\n",
       "      <td>526401</td>\n",
       "      <td>571.0</td>\n",
       "      <td>571.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>129</th>\n",
       "      <td>201712</td>\n",
       "      <td>436105</td>\n",
       "      <td>616.0</td>\n",
       "      <td>616.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>130</th>\n",
       "      <td>201712</td>\n",
       "      <td>194450</td>\n",
       "      <td>410.0</td>\n",
       "      <td>410.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>201712</td>\n",
       "      <td>963845</td>\n",
       "      <td>332.0</td>\n",
       "      <td>331.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>201712</td>\n",
       "      <td>349023</td>\n",
       "      <td>1431.0</td>\n",
       "      <td>1430.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>133</th>\n",
       "      <td>201712</td>\n",
       "      <td>743957</td>\n",
       "      <td>1044.0</td>\n",
       "      <td>1044.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>134</th>\n",
       "      <td>201712</td>\n",
       "      <td>923841</td>\n",
       "      <td>928.0</td>\n",
       "      <td>928.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>201712</td>\n",
       "      <td>250658</td>\n",
       "      <td>291.0</td>\n",
       "      <td>291.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>201712</td>\n",
       "      <td>714150</td>\n",
       "      <td>294.0</td>\n",
       "      <td>294.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>201712</td>\n",
       "      <td>395234</td>\n",
       "      <td>154.0</td>\n",
       "      <td>154.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>138</th>\n",
       "      <td>201712</td>\n",
       "      <td>842246</td>\n",
       "      <td>211.0</td>\n",
       "      <td>211.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139</th>\n",
       "      <td>201712</td>\n",
       "      <td>136916</td>\n",
       "      <td>248.0</td>\n",
       "      <td>247.8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>140 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     predict_date  class_id  predict_quantity     tmp\n",
       "0          201712    281792             658.0   658.0\n",
       "1          201712    682651             449.0   449.4\n",
       "2          201712    603972             647.0   646.8\n",
       "3          201712    221795             568.0   568.4\n",
       "4          201712    482497             286.0   285.6\n",
       "5          201712    379265             480.0   480.2\n",
       "6          201712    687270             659.0   659.4\n",
       "7          201712    890189            1901.0  1901.2\n",
       "8          201712    654134             895.0   894.6\n",
       "9          201712    739296            1260.0  1260.0\n",
       "10         201712    437063             171.0   170.8\n",
       "11         201712    453752             322.0   322.0\n",
       "12         201712    209945             202.0   201.6\n",
       "13         201712    732758             263.0   263.2\n",
       "14         201712    683364             134.0   134.4\n",
       "15         201712    527765             101.0   100.8\n",
       "16         201712    614059             482.0   481.6\n",
       "17         201712    527809             256.0   256.2\n",
       "18         201712    401052             204.0   204.4\n",
       "19         201712    510309             171.0   170.8\n",
       "20         201712    290854             325.0   324.8\n",
       "21         201712    416749             328.0   327.6\n",
       "22         201712    587678             288.0   288.4\n",
       "23         201712    651347             294.0   294.0\n",
       "24         201712    973106             188.0   187.6\n",
       "25         201712    854079             280.0   280.0\n",
       "26         201712    713651             305.0   305.2\n",
       "27         201712    468392             255.0   254.8\n",
       "28         201712    169673             235.0   235.2\n",
       "29         201712    379876             211.0   211.4\n",
       "..            ...       ...               ...     ...\n",
       "110        201712    417803             171.0   170.8\n",
       "111        201712    492952             255.0   254.8\n",
       "112        201712    580634             377.0   376.6\n",
       "113        201712    559132             182.0   182.0\n",
       "114        201712    961362             116.0   116.2\n",
       "115        201712    354068             862.0   862.4\n",
       "116        201712    348641             526.0   526.4\n",
       "117        201712    861459             370.0   369.6\n",
       "118        201712    950264            1606.0  1605.8\n",
       "119        201712    760412             106.0   106.4\n",
       "120        201712    560265             134.0   134.4\n",
       "121        201712    376193             160.0   159.6\n",
       "122        201712    872180             204.0   204.4\n",
       "123        201712    621073            1644.0  1643.6\n",
       "124        201712    516750             111.0   110.6\n",
       "125        201712    270690             966.0   966.0\n",
       "126        201712    178529             256.0   256.2\n",
       "127        201712    786351             221.0   221.2\n",
       "128        201712    526401             571.0   571.2\n",
       "129        201712    436105             616.0   616.0\n",
       "130        201712    194450             410.0   410.2\n",
       "131        201712    963845             332.0   331.8\n",
       "132        201712    349023            1431.0  1430.8\n",
       "133        201712    743957            1044.0  1044.4\n",
       "134        201712    923841             928.0   928.2\n",
       "135        201712    250658             291.0   291.2\n",
       "136        201712    714150             294.0   294.0\n",
       "137        201712    395234             154.0   154.0\n",
       "138        201712    842246             211.0   211.4\n",
       "139        201712    136916             248.0   247.8\n",
       "\n",
       "[140 rows x 4 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dec = pd.merge(dec, nov_pred[['class_id','tmp']], how='left', on='class_id')\n",
    "dec['predict_quantity'] = dec['tmp'].round(0)\n",
    "dec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "dec = dec.drop('tmp',1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>predict_date</th>\n",
       "      <th>class_id</th>\n",
       "      <th>predict_quantity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>201712</td>\n",
       "      <td>281792</td>\n",
       "      <td>658.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>201712</td>\n",
       "      <td>682651</td>\n",
       "      <td>449.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>201712</td>\n",
       "      <td>603972</td>\n",
       "      <td>647.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>201712</td>\n",
       "      <td>221795</td>\n",
       "      <td>568.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>201712</td>\n",
       "      <td>482497</td>\n",
       "      <td>286.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>201712</td>\n",
       "      <td>379265</td>\n",
       "      <td>480.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>201712</td>\n",
       "      <td>687270</td>\n",
       "      <td>659.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>201712</td>\n",
       "      <td>890189</td>\n",
       "      <td>1901.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>201712</td>\n",
       "      <td>654134</td>\n",
       "      <td>895.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>201712</td>\n",
       "      <td>739296</td>\n",
       "      <td>1260.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>201712</td>\n",
       "      <td>437063</td>\n",
       "      <td>171.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>201712</td>\n",
       "      <td>453752</td>\n",
       "      <td>322.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>201712</td>\n",
       "      <td>209945</td>\n",
       "      <td>202.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>201712</td>\n",
       "      <td>732758</td>\n",
       "      <td>263.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>201712</td>\n",
       "      <td>683364</td>\n",
       "      <td>134.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>201712</td>\n",
       "      <td>527765</td>\n",
       "      <td>101.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>201712</td>\n",
       "      <td>614059</td>\n",
       "      <td>482.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>201712</td>\n",
       "      <td>527809</td>\n",
       "      <td>256.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>201712</td>\n",
       "      <td>401052</td>\n",
       "      <td>204.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>201712</td>\n",
       "      <td>510309</td>\n",
       "      <td>171.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>201712</td>\n",
       "      <td>290854</td>\n",
       "      <td>325.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>201712</td>\n",
       "      <td>416749</td>\n",
       "      <td>328.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>201712</td>\n",
       "      <td>587678</td>\n",
       "      <td>288.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>201712</td>\n",
       "      <td>651347</td>\n",
       "      <td>294.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>201712</td>\n",
       "      <td>973106</td>\n",
       "      <td>188.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>201712</td>\n",
       "      <td>854079</td>\n",
       "      <td>280.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>201712</td>\n",
       "      <td>713651</td>\n",
       "      <td>305.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>201712</td>\n",
       "      <td>468392</td>\n",
       "      <td>255.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>201712</td>\n",
       "      <td>169673</td>\n",
       "      <td>235.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>201712</td>\n",
       "      <td>379876</td>\n",
       "      <td>211.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>110</th>\n",
       "      <td>201712</td>\n",
       "      <td>417803</td>\n",
       "      <td>171.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>201712</td>\n",
       "      <td>492952</td>\n",
       "      <td>255.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>201712</td>\n",
       "      <td>580634</td>\n",
       "      <td>377.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>201712</td>\n",
       "      <td>559132</td>\n",
       "      <td>182.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>201712</td>\n",
       "      <td>961362</td>\n",
       "      <td>116.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>201712</td>\n",
       "      <td>354068</td>\n",
       "      <td>862.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>201712</td>\n",
       "      <td>348641</td>\n",
       "      <td>526.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>201712</td>\n",
       "      <td>861459</td>\n",
       "      <td>370.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>118</th>\n",
       "      <td>201712</td>\n",
       "      <td>950264</td>\n",
       "      <td>1606.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>201712</td>\n",
       "      <td>760412</td>\n",
       "      <td>106.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>120</th>\n",
       "      <td>201712</td>\n",
       "      <td>560265</td>\n",
       "      <td>134.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>121</th>\n",
       "      <td>201712</td>\n",
       "      <td>376193</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>122</th>\n",
       "      <td>201712</td>\n",
       "      <td>872180</td>\n",
       "      <td>204.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>201712</td>\n",
       "      <td>621073</td>\n",
       "      <td>1644.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>201712</td>\n",
       "      <td>516750</td>\n",
       "      <td>111.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>125</th>\n",
       "      <td>201712</td>\n",
       "      <td>270690</td>\n",
       "      <td>966.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>126</th>\n",
       "      <td>201712</td>\n",
       "      <td>178529</td>\n",
       "      <td>256.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>127</th>\n",
       "      <td>201712</td>\n",
       "      <td>786351</td>\n",
       "      <td>221.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>128</th>\n",
       "      <td>201712</td>\n",
       "      <td>526401</td>\n",
       "      <td>571.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>129</th>\n",
       "      <td>201712</td>\n",
       "      <td>436105</td>\n",
       "      <td>616.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>130</th>\n",
       "      <td>201712</td>\n",
       "      <td>194450</td>\n",
       "      <td>410.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>201712</td>\n",
       "      <td>963845</td>\n",
       "      <td>332.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>201712</td>\n",
       "      <td>349023</td>\n",
       "      <td>1431.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>133</th>\n",
       "      <td>201712</td>\n",
       "      <td>743957</td>\n",
       "      <td>1044.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>134</th>\n",
       "      <td>201712</td>\n",
       "      <td>923841</td>\n",
       "      <td>928.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>135</th>\n",
       "      <td>201712</td>\n",
       "      <td>250658</td>\n",
       "      <td>291.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>201712</td>\n",
       "      <td>714150</td>\n",
       "      <td>294.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>201712</td>\n",
       "      <td>395234</td>\n",
       "      <td>154.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>138</th>\n",
       "      <td>201712</td>\n",
       "      <td>842246</td>\n",
       "      <td>211.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139</th>\n",
       "      <td>201712</td>\n",
       "      <td>136916</td>\n",
       "      <td>248.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>140 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     predict_date  class_id  predict_quantity\n",
       "0          201712    281792             658.0\n",
       "1          201712    682651             449.0\n",
       "2          201712    603972             647.0\n",
       "3          201712    221795             568.0\n",
       "4          201712    482497             286.0\n",
       "5          201712    379265             480.0\n",
       "6          201712    687270             659.0\n",
       "7          201712    890189            1901.0\n",
       "8          201712    654134             895.0\n",
       "9          201712    739296            1260.0\n",
       "10         201712    437063             171.0\n",
       "11         201712    453752             322.0\n",
       "12         201712    209945             202.0\n",
       "13         201712    732758             263.0\n",
       "14         201712    683364             134.0\n",
       "15         201712    527765             101.0\n",
       "16         201712    614059             482.0\n",
       "17         201712    527809             256.0\n",
       "18         201712    401052             204.0\n",
       "19         201712    510309             171.0\n",
       "20         201712    290854             325.0\n",
       "21         201712    416749             328.0\n",
       "22         201712    587678             288.0\n",
       "23         201712    651347             294.0\n",
       "24         201712    973106             188.0\n",
       "25         201712    854079             280.0\n",
       "26         201712    713651             305.0\n",
       "27         201712    468392             255.0\n",
       "28         201712    169673             235.0\n",
       "29         201712    379876             211.0\n",
       "..            ...       ...               ...\n",
       "110        201712    417803             171.0\n",
       "111        201712    492952             255.0\n",
       "112        201712    580634             377.0\n",
       "113        201712    559132             182.0\n",
       "114        201712    961362             116.0\n",
       "115        201712    354068             862.0\n",
       "116        201712    348641             526.0\n",
       "117        201712    861459             370.0\n",
       "118        201712    950264            1606.0\n",
       "119        201712    760412             106.0\n",
       "120        201712    560265             134.0\n",
       "121        201712    376193             160.0\n",
       "122        201712    872180             204.0\n",
       "123        201712    621073            1644.0\n",
       "124        201712    516750             111.0\n",
       "125        201712    270690             966.0\n",
       "126        201712    178529             256.0\n",
       "127        201712    786351             221.0\n",
       "128        201712    526401             571.0\n",
       "129        201712    436105             616.0\n",
       "130        201712    194450             410.0\n",
       "131        201712    963845             332.0\n",
       "132        201712    349023            1431.0\n",
       "133        201712    743957            1044.0\n",
       "134        201712    923841             928.0\n",
       "135        201712    250658             291.0\n",
       "136        201712    714150             294.0\n",
       "137        201712    395234             154.0\n",
       "138        201712    842246             211.0\n",
       "139        201712    136916             248.0\n",
       "\n",
       "[140 rows x 3 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "dec.to_csv(\"../../result/Dec_NovPred_multiBy1.4.csv\",index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
